/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sellcar;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;

/**
 *
 * @author Marcos
 */
public class ListaPesquisa {
    private Connection connection = new ConnectionFactory().getConnection();
    private ResultSet rs;
    private PreparedStatement stmt;
    
//    List<Login> lista = new ArrayList<Login>();
//    
//    public List<Login> primeiro() throws SQLException
//    {
//        Login login = new Login();
//        String sql = "SELECT id_usuario,desc_login,senha FROM tb_usuario";
//        stmt = connection.prepareStatement(sql);
//        rs = stmt.executeQuery(sql);
//        
//        rs.first();
//        login.setUsuario(rs.getString("desc_login"));
//        login.setSenha(rs.getString("senha"));
//        lista.add(login);
//        
//        return lista;
//        
//    }
//    
//    public List<Login> proximo() throws SQLException
//    {
//        Login login = new Login();
//        String sql = "SELECT id_usuario,desc_login,senha FROM tb_usuario";
//        stmt = connection.prepareStatement(sql);
//        rs = stmt.executeQuery(sql);
//        
//        while(rs.next()){
//            login.setUsuario(rs.getString("desc_login"));
//            login.setSenha(rs.getString("senha"));
//            lista.add(login);
//        }
//        
//        return lista;
//        
//    }
    
    ResultSet rsMostrar = null;
    int atual = 0;
    int total = 0;

    public ResultSet mostrar() throws SQLException {

        PreparedStatement stmt;

        //usuario.proximo();


//                Login usuario_bd = usuario.lista.get(0);
//                Login senha_bd = usuario.lista.get(0);     
        String sql = "SELECT id_usuario,desc_login,senha FROM tb_usuario";
        stmt = connection.prepareStatement(sql);
        rsMostrar = stmt.executeQuery(sql);
        while (rsMostrar.next()) {
            total = total + 1;
            JOptionPane.showMessageDialog(null, rsMostrar.getString(1));
        }
        rsMostrar.first();
        return rsMostrar;

    }
    
    public ResultSet mostrar_proximo() throws SQLException {      

        rsMostrar.next();
        return rsMostrar;

    }
}
